// Quantitative Angiogram Analysis System
//
// Copyright ?Ping Zou, 2006
// sg71.cherub@gmail.com

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

using WeifenLuo.WinFormsUI;
using eee.Sheffield.PZ.Imaging;
using eee.Sheffield.PZ.Imaging.ImageIO;

using eee.Sheffield.PZ.Math;

namespace eee.Sheffield.PZ.QAAS
{
    /// <summary>
    /// test methods of main form
    /// </summary>
    partial class MainForm
    {
        private void TestMethod()
        {
            PostProcessingTrackingResults post = new PostProcessingTrackingResults();
            string pathName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Philip Practical Test\\1";
            string imageFileName = pathName + "\\1.bmp";
            Bitmap srcImage = new Bitmap(imageFileName);
            Bitmap tempImage;

            post.DstImage = srcImage;
            post.SrcImage = srcImage;

            post.PathName = pathName;
            post.ReadFile();

            // remove duplicate
            System.Console.WriteLine("total length: " + post.TotalLength());
            post.RemoveDuplicates();
            System.Console.WriteLine("total length: " + post.TotalLength());

            // remove short results
            post.LengthThreshold = 3;
            post.RemoveShortResults();
            System.Console.WriteLine("total length: " + post.TotalLength());
            tempImage = post.DrawTrackResultsCentreLines(post.DstTrackResultList, srcImage);
            tempImage.Save(pathName + "\\post 1.bmp", ImageFormat.Bmp);

            // remove disconnected centre points
            post.RemoveDisconnectedCPs(3);
            System.Console.WriteLine("total length: " + post.TotalLength());
            tempImage = post.DrawTrackResultsCentreLines(post.DstTrackResultList, srcImage);
            tempImage.Save(pathName + "\\post 2.bmp", ImageFormat.Bmp);

            // extend branches to its roots
            post.ExtendBranchesToRoot();
            tempImage = post.DrawTrackResultsCentreLines();
            tempImage.Save(pathName + "\\temp.bmp", ImageFormat.Bmp);

            // find leafs and roots
            post.FindLeaves();
            post.FindRoots();

            // init flows
            post.InitializeFlow();
            bool isBalance = post.CheckJointFlow();
            bool containsAll = post.CheckJoint();

            // find flow routes, from roots to leaves
            post.FindRootToLeafRoute();
            containsAll = post.CheckRoutes();

            // save diag
            System.Console.WriteLine("total length: " + post.TotalLength());
            post.WriteDiagram(pathName + "\\diagram.txt");
        }
    }
}
